/* GUI CONVERTED from rcsomt.p (converter v1.76) Mon Jun 10 11:46:19 2002 */
/* rcsomt.p - Release Management Customer Schedules                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.17.3.14 $                                                     */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 09/30/92   BY: WUG *G462*                */
/* REVISION: 7.3      LAST MODIFIED: 01/26/93   BY: bcm *G429*                */
/* REVISION: 7.3      LAST MODIFIED: 02/18/93   BY: afs *G804*                */
/* REVISION: 7.3      LAST MODIFIED: 06/16/93   BY: WUG *GB74*                */
/* REVISION: 7.3      LAST MODIFIED: 06/25/93   BY: WUG *GC73*                */
/* REVISION: 7.3      LAST MODIFIED: 07/07/93   BY: WUG *GD25*                */
/* REVISION: 7.3      LAST MODIFIED: 08/13/93   BY: WUG *GE19*                */
/* REVISION: 7.4      LAST MODIFIED: 08/11/93   BY: bcm *H064*                */
/* REVISION: 7.4      LAST MODIFIED: 09/21/93   BY: WUG *H130*                */
/* REVISION: 7.4      LAST MODIFIED: 09/21/93   BY: WUG *H140*                */
/* REVISION: 7.4      LAST MODIFIED: 09/28/93   BY: WUG *H141*                */
/* REVISION: 7.4      LAST MODIFIED: 12/23/93   BY: WUG *GI32*                */
/* REVISION: 7.4      LAST MODIFIED: 04/14/94   BY: WUG *GJ35*                */
/* REVISION: 7.3      LAST MODIFIED: 04/21/94   BY: WUG *GJ48*                */
/* REVISION: 7.3      LAST MODIFIED: 09/06/94   BY: dpm *GL94*                */
/* REVISION  7.4      LAST MODIFIED  10/29/94   BY: bcm *FT06*                */
/* REVISION: 7.4      LAST MODIFIED: 10/31/94   BY: mmp *H579*                */
/* REVISION: 7.4      LAST MODIFIED: 11/30/94   BY: afs *H611*                */
/* REVISION: 8.5      LAST MODIFIED: 12/13/94   BY: mwd *J034*                */
/* REVISION: 7.4      LAST MODIFIED: 12/15/94   BY: rxm *GN16*                */
/* REVISION: 7.4      LAST MODIFIED: 04/12/95   BY: rxm *G0K8*                */
/* REVISION: 7.3      LAST MODIFIED: 04/27/95   BY: bcm *G0LH*                */
/* REVISION: 7.4      LAST MODIFIED: 04/27/95   BY: yep *G0KL*                */
/* REVISION: 8.5      LAST MODIFIED: 04/24/95   BY: dpm *J044*                */
/* REVISION: 8.5      LAST MODIFIED: 10/26/95   BY: dpm *J08Y*                */
/* REVISION: 7.3      LAST MODIFIED: 08/15/95   BY: bcm *G0TB*                */
/* REVISION: 7.4      LAST MODIFIED: 09/15/95   BY: vrn *G0VP*                */
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: vrn *G1LV*                */
/* REVISION: 8.5      LAST MODIFIED: 05/29/96   BY: ame *J0PC*                */
/* REVISION: 8.5      LAST MODIFIED: 06/10/96   BY: ajw *J0RV*                */
/* REVISION: 8.5      LAST MODIFIED: 07/19/96   BY: *G29C* Ajit Deodhar       */
/* REVISION: 8.5      LAST MODIFIED: 09/18/96   BY: *G2FN* Suresh Nayak       */
/* REVISION: 8.6      LAST MODIFIED: 09/20/96   BY: TSI *K005*                */
/* REVISION: 8.6      LAST MODIFIED: 11/11/96   BY: *G2HY* Ajit Deodhar       */
/* REVISION: 8.6      LAST MODIFIED: 02/12/97   BY: *J1HR* Ajit Deodhar       */
/* REVISION: 8.6      LAST MODIFIED: 06/03/97   BY: *K0DQ* Taek-Soo Chang     */
/* REVISION: 8.6      LAST MODIFIED: 08/08/97   BY: *J1YQ* Suresh Nayak       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *GG01*                    */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Bill Reckard       */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Robin McCarthy     */
/* REVISION: 8.6E     LAST MODIFIED: 06/22/99   BY: *K21B* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 11/29/99   BY: *N004* Patrick Rowan      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/06/00   BY: *N0RG* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 11/19/00   BY: *M0WC* Rajesh Thomas      */
/* Revision: 1.17.3.8      BY: Katie Hilbert     DATE: 04/01/01  ECO: *P002*  */
/* Revision: 1.17.3.9      BY: Anil Sudhakaran   DATE: 06/13/01  ECO: *M1B5*  */
/* Revision: 1.17.3.10     BY: Nikita Joshi      DATE: 09/14/01  ECO: *M1KS*  */
/* Revision: 1.17.3.12     BY: Patrick Rowan     DATE: 01/08/01  ECO: *P00G*  */
/* Revision: 1.17.3.13     BY: Ashish M.         DATE: 05/14/02  ECO: *P06M*  */
/* $Revision: 1.17.3.14 $  BY: Jean Miller       DATE: 06/10/02  ECO: *P065*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}
{pxmaint.i} /* PERSISTENT PROCEDURE PROGRAM MANAGER */
{pxphdef.i sosoxr} /* DEFINES HANDLE FOR SO HEADER ROP */

/* SCHEDULED ORDER MAINT */

define new shared variable so_db           like dc_name.
define new shared variable all_days        like soc_all_days.
define new shared variable all_avail       like soc_all_avl.
define new shared variable sotax_trl       like tax_trl.
define new shared variable tax_recno       as   recid.
define new shared variable cmtindx         like cmt_indx.
define new shared variable order-shipfrom  like scx_shipfrom   no-undo.
define new shared variable impexp          like mfc_logical    no-undo.
define new shared variable tax_in          like ad_tax_in.
define new shared variable undo_sosomtb    like mfc_logical.
define new shared variable so_recno        as   recid.
define new shared variable new_order       like mfc_logical.
define new shared variable global_order    as   character.

define new shared frame so.
define new shared frame so1.
define new shared frame so2.
define new shared frame sod.
define new shared frame sod1.
define new shared frame sod2.
define new shared frame so3.

define variable sonbr           like so_nbr.
define variable tax_date        like tax_effdate.
define variable del-yn          like mfc_logical.
define variable yn              like mfc_logical.
define variable line            as   integer.
define variable scx_recid       as   recid.
define variable so_recid        as   recid.
define variable addr            as   character.
define variable old_bill        as   character.
define variable old_tr_days     as   decimal              no-undo.
define variable imp-okay        like mfc_logical          no-undo.
define variable impexp_edit     like mfc_logical          no-undo.
define variable upd_okay        like mfc_logical          no-undo.
define variable impexp_order    like so_nbr               no-undo.
define variable endok           as  logical initial false no-undo.
define variable using_seq_schedules  like mfc_logical     no-undo.
define variable seq_sched_order like mfc_logical          no-undo.
define variable taxable         like ad_taxable           no-undo.
define variable taxClass        like ad_taxc              no-undo.
define variable taxUsage        like ad_tax_usage         no-undo.
define variable l_edittax       like mfc_logical          no-undo.

define buffer scxref for scx_ref.

/* CONSIGNMENT VARIABLES */
define variable proc_id as character no-undo.
{socnvars.i}

/* TAX MANAGEMENT FORM */
FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
so_tax_usage colon 25
   so_tax_env   colon 25
 SKIP(.4)  /*GUI*/
with frame set_tax row 8 centered overlay side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-set_tax-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame set_tax = F-set_tax-title.
 RECT-FRAME-LABEL:HIDDEN in frame set_tax = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame set_tax =
  FRAME set_tax:HEIGHT-PIXELS - RECT-FRAME:Y in frame set_tax - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME set_tax = FRAME set_tax:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame set_tax:handle).

{gptxcdec.i}    /* DECLARATIONS FOR gptxcval.i */

if no then find first sod_det no-lock.

{rcordfrm.i}

/* VARIABLE DEFINITIONS FOR gpfile.i */
{gpfilev.i}

/* DETERMINE IF SEQUENCE SCHEDULES IS INSTALLED */
{gpfile.i &file_name = """"rcf_ctrl""""}
if can-find (mfc_ctrl where
   mfc_field = "enable_sequence_schedules"  and
   mfc_logical) and file_found then
   using_seq_schedules = yes.

find first soc_ctrl no-lock.
find first gl_ctrl no-lock.

so_db = global_db.
socmmts = soc_hcmmts.

/* DETERMINE IF CUSTOMER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
   "(input ENABLE_CUSTOMER_CONSIGNMENT,
     input 10,
     input ADG,
     input CUST_CONSIGN_CTRL_TABLE,
     output using_cust_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   find first soc_ctrl no-lock.

   hide frame sod2.
   hide frame sod1.
   hide frame sod.
   hide frame so2.
   hide frame so1.
   hide frame so3.

   block_1:
   do with frame so:

      prompt-for
         scx_shipfrom scx_shipto scx_order
      editing:

         if frame-field = "scx_shipfrom" then do:
            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1"
               scx_shipfrom "input frame so scx_shipfrom"}

            if recno <> ? then do:
               find si_mstr where si_site = scx_shipfrom no-lock.
               find ad_mstr where ad_addr = scx_shipto
                  no-lock no-error.

               display
                  scx_shipfrom
                  scx_shipto
                  ad_name  when (available ad_mstr)
                  scx_order.
            end.

            if lastkey = keycode("F10")
               or lastkey = keycode("CURSOR-DOWN")
            then do:
               find last scx_ref where scx_type = 1
                  and scx_shipfrom <= input frame so scx_shipfrom
                  and scx_shipto <= input frame so scx_shipto
                  no-lock no-error.

               recno = recid(scx_ref).
            end.

            else
            if lastkey = keycode("F9")
               or lastkey = keycode("CURSOR-UP")
            then do:
               find first scx_ref where scx_type = 1
                  and scx_shipfrom >= input frame so scx_shipfrom
                  and scx_shipto >= input frame so scx_shipto
                  no-lock no-error.

               recno = recid(scx_ref).
            end.

         end. /* if scx_shipfrom */

         else
         if frame-field = "scx_shipto" then do:

            {mfnp05.i scx_ref scx_shipfrom "scx_type = 1
                     and scx_shipfrom = input frame so scx_shipfrom"
               scx_shipto "input frame so scx_shipto"}

            if recno <> ? then do:
               find si_mstr where si_site = scx_shipfrom no-lock.
               find ad_mstr where ad_addr = scx_shipto
                  no-lock no-error.

               display
                  scx_shipfrom
                  scx_shipto
                  ad_name when (available ad_mstr)
                  scx_order.
            end.

            if lastkey = keycode("F10")
               or lastkey = keycode("CURSOR-DOWN")
            then do:
               find last scx_ref where scx_type = 1
                  and scx_shipfrom = input frame so scx_shipfrom
                  and scx_shipto <= input frame so scx_shipto
                  no-lock no-error.

               recno = recid(scx_ref).
            end.

            else
            if lastkey = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
            then do:
               find first scx_ref where scx_type = 1
                  and scx_shipfrom = input frame so scx_shipfrom
                  and scx_shipto >= input frame so scx_shipto
                  no-lock no-error.

               recno = recid(scx_ref).
            end.

         end.

         else
         if frame-field = "scx_order" then do:

            {mfnp05.i scx_ref scx_order "scx_type = 1"
               scx_order "input frame so scx_order"}

            if recno <> ? then do:
               find si_mstr where si_site = scx_shipfrom no-lock.
               find ad_mstr where ad_addr = scx_shipto
                  no-lock no-error.

               display
                  scx_shipfrom
                  scx_shipto
                  ad_name when (available ad_mstr)
                  scx_order.
            end.

            recno = ?.

         end.

         else do:
            status input.
            readkey.
            apply lastkey.
         end.

      end.

      /*! FIND EXISTING ORDER INFO IF IT EXISTS */
      if input scx_order > "" then do:

         find so_mstr where so_nbr = input scx_order
            no-lock no-error.

         if available so_mstr then do:

            order-shipfrom = input scx_shipfrom.

            /* WE DO NOT DISPLAY THE SHIPFROM IN CASE THERE
            ARE NOT ANY LINES YET AND THE USER HAS CHANGED
            THE AR SITE (so_site) AND INTENDS FOR IT TO BE
            DIFFERENT THAN THE SHIP-FROM SITE */

            /* IF A LINE EXISTS, USE ITS INFORMATION */
            find first scx_ref where scx_type = 1
               and scx_order = input scx_order
            no-lock no-error.

            if available scx_ref then do:
               order-shipfrom = scx_shipfrom.
               display
                  scx_shipfrom
                  scx_shipto
               with frame so.
            end.

         end.

      end.

      if input scx_shipfrom > "" and input scx_shipto > ""
         and input scx_order  = ""
      then
         order-shipfrom = input scx_shipfrom.

      /* VALIDATE */
      find si_mstr where si_site = input scx_shipfrom
         no-lock no-error.
      if not available si_mstr then do:
         /* Site Does not exist */
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input si_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         /* USER DOES NOT HAVE ACCESS TO SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         undo, retry.
      end.

      /* IF NOT CONNECTED, ISSUE ERROR AND UNDO */
      if si_db <> global_db and
         not connected(si_db)
      then do:
         /* DATABASE NOT AVAILABLE */
         {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1="si_db" &MSGARG2="" &MSGARG3="" &MSGARG4="" &MSGARG5=""}
         undo, retry.
      end.

      find ad_mstr where ad_addr = input scx_shipto no-lock no-error.
      if not available ad_mstr then do:
         /* Ship to does not exist */
         {pxmsg.i &MSGNUM=8501 &ERRORLEVEL=3}
         undo, retry.
      end.

      find first ls_mstr where ls_addr = ad_addr
         and (ls_type = "customer" or ls_type = "ship-to"
         or ls_type = "dock")
      no-lock no-error.

      if not available ls_mstr then do:
         /* Invalid Customer or ship-to */
         {pxmsg.i &MSGNUM=8156 &ERRORLEVEL=3}
         bell.
         undo, retry.
      end.

      /* If the address is of type "dock" then find the corresponding
       * Ship-to or sold-to address and assign the tax class/usage/
       * Taxable status from that address */
      if ls_type = "dock" then do:
         for first ls_mstr where ls_addr = ad_ref and
         (ls_type = "ship-to" or ls_type = "customer")
         no-lock:
            for first ad_mstr where ad_addr = ls_addr
            no-lock: end.
         end. /* for first ls_mstr.... */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* if ls_type = "dock" */

      assign
         taxClass = ad_taxc
         taxUsage = ad_tax_usage
         taxable = ad_taxable.

      find cm_mstr where cm_addr = ad_addr no-lock no-error.

      do while not available cm_mstr and ad_ref > "":
         addr = ad_ref.
         find ad_mstr where ad_addr = addr no-lock.
         find cm_mstr where cm_addr = ad_addr no-lock no-error.
      end.

      find ad_mstr where ad_addr = input scx_shipto no-lock no-error.

      display
         ad_name.

      find so_mstr where so_nbr = input scx_order no-lock no-error.

      if available so_mstr then do:

         if not so_sched then do:
            /* Order was created from Sales Order Maintenance */
            {pxmsg.i &MSGNUM=8157 &ERRORLEVEL=3}
            bell.
            undo, retry.
         end.

         new_order = false.
         recno = recid(so_mstr).

         /* MUST BE IN ORDER DATABASE*/
         if trim(substring(so_conrep,15,20)) <> global_db then do:
            /* YOU MUST BE IN DATABASE */
            {pxmsg.i &MSGNUM=8148 &ERRORLEVEL=3
                     &MSGARG1=trim(substring(so_conrep,15))}
            undo, retry.
         end.
      end.

      else do:

         new_order = true.

         if input scx_order = "" then do:

            find first scx_ref where scx_type = 1
               and scx_shipfrom = input scx_shipfrom
               and scx_shipto   = input scx_shipto
            no-lock no-error.

            if available scx_ref then do:
               /* ORDER ALREADY EXISTS FOR SHIP-FROM AND SHIP-TO, ORDER: */
               {pxmsg.i &MSGNUM=1607 &ERRORLEVEL=2 &MSGARG1=scx_order}
            end.

            do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

               /* Get next sales order number with prefix */
               {mfnctrlc.i soc_ctrl soc_so_pre soc_so so_mstr so_nbr sonbr}
               display sonbr @ scx_order.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.


         end. /* end of if input scx_order = ""          */

      end. /* end of else do if available so_mstr        */
   end. /*end of block_1                                 */

   block_2:
   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


      find first soc_ctrl no-lock.

      if not new_order then do:

         find so_mstr where recid(so_mstr) = recno exclusive-lock .

         if so_ship <> input scx_shipto
         then do:

            assign
               l_edittax = no
               so_ship   = input scx_shipto.

            if  not batchrun
            then do:

               /* SHIP-TO CHANGED; UPDATE TAX DATA? */
               {pxmsg.i &MSGNUM=2351 &ERRORLEVEL=1 &CONFIRM=l_edittax}

               if l_edittax then do:

                  /* LOAD DEFAULT TAX CLASS & USAGE */
                  for first ad_mstr
                     fields (ad_addr ad_city ad_county
                             ad_inv_mthd ad_lang ad_name
                             ad_pst_id ad_ref ad_state
                             ad_taxable ad_taxc ad_tax_in
                             ad_tax_usage)
                     where ad_addr = so_ship
                  no-lock: end.

                  if not available ad_mstr then
                     for first ad_mstr
                        fields (ad_addr ad_city ad_county
                                ad_inv_mthd ad_lang ad_name
                                ad_pst_id ad_ref ad_state
                                ad_taxable ad_taxc ad_tax_in
                                ad_tax_usage)
                        where ad_addr = so_cust
                     no-lock: end.

                  if available ad_mstr then
                     assign
                        so_taxable   = ad_taxable
                        so_tax_usage = ad_tax_usage
                        so_taxc      = ad_taxc
                        so_tax_env   = "".

               end.  /* IF l_edittax */

            end.  /* IF NOT batchrun */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* IF so_ship <> input scx_shipto */

      end.

      else do:

         /* Creating new record */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

         create so_mstr.
         assign
            so_nbr = input scx_order
            so_cust = cm_addr
            so_ship = ad_addr
            so_bill = if cm_bill > "" then cm_bill else cm_addr
            so_site = input scx_shipfrom
            so_fob = soc_fob
            so_conf_date = today
            so_disc_pct = cm_disc_pct
            so_shipvia  = cm_shipvia
            so_partial  = cm_partial
            so_rmks     = cm_rmks
            so_taxable  = taxable
            so_taxc     = taxClass
            so_tax_usage = taxUsage
            so_pst      = cm_pst
            so_fst_id   = cm_fst_id
            so_pst_id   = ad_pst_id
            so_fr_list   = cm_fr_list
            so_fr_terms  = cm_fr_terms
            so_fr_min_wt = cm_fr_min_wt
            so_lang     = ad_lang
            so_conrep   = fill(" ",14) + string(so_db,"x(20)")
            so_cum_acct = true
            so_userid   = global_userid
            so_sched = yes.

         assign
            recno          = recid(so_mstr)
            order-shipfrom = input scx_shipfrom.

         find ad_mstr where ad_addr = so_bill no-lock no-error.
         if available ad_mstr and ad_inv_mthd <> "" then
            so_inv_mthd = ad_inv_mthd.
         else do:
            find ad_mstr where ad_addr = so_ship no-lock no-error.
            if available ad_mstr and ad_inv_mthd <> "" then
               so_inv_mthd = ad_inv_mthd.
            else do:
               find ad_mstr where ad_addr = so_cust no-lock no-error.
               if available ad_mstr and ad_inv_mthd <> "" then
                  so_inv_mthd = ad_inv_mthd.
            end.
         end.
         find ad_mstr where ad_addr = so_ship no-lock no-error.

         /* ADD DEFAULT AUTO_POST_INVOICE FROM CONTROL FILE */
         find mfc_ctrl where mfc_field = "rcc_auto_post"
            no-lock no-error.
         if available mfc_ctrl then
         assign
            substring(so_inv_mthd,2,1) = substring(string(mfc_logical),1,1).

         define buffer bill_cm for cm_mstr.
         do for bill_cm:
            find bill_cm where bill_cm.cm_addr = so_bill no-lock.
            assign
               so_cr_terms = bill_cm.cm_cr_terms
               so_curr     = bill_cm.cm_curr.

            if bill_cm.cm_ar_acct <> "" then
               assign
                  so_ar_acct = bill_cm.cm_ar_acct
                  so_ar_sub = bill_cm.cm_ar_sub
                  so_ar_cc = bill_cm.cm_ar_cc.
            else
               assign
                  so_ar_acct = gl_ar_acct
                  so_ar_sub = gl_ar_sub
                  so_ar_cc = gl_ar_cc.
         end.

         /* INITIALIZE TRAILER CODES FROM CONTROL FILE FOR */
         /* NEW ORDERS ONLY */
         {gpgettrl.i &hdr_file="so" &ctrl_file="soc"}

         if new_order
            and soc_use_frt_trl_cd
         then do:
            for first fr_mstr
               fields (fr_curr fr_list fr_site fr_trl_cd)
               where fr_list = so_fr_list
                 and fr_site = so_site
                 and fr_curr = so_curr
            no-lock:
               so_trl1_cd = fr_trl_cd.
            end. /* FOR FIRST fr_mstr */
         end. /* IF new-order and ... */

         so_fix_rate = no.
         tax_in = ad_tax_in.

      /* INITIALIZE CONSIGNMENT RECORD IF CUSTOMER CONSIGNMENT */
      /* IS BEING USED.                                        */
      if using_cust_consignment then do:
         proc_id = "init".
         {gprunmo.i
            &program=""socnso.p""
            &module="ACN"
            &param="""(input proc_id,
              input so_nbr,
              input so_ship,
              input so_site,
              input yes)"""}
      end.  /* if using_cust_consignment */

      /* INITIALIZE TRANSPORT DAYS FROM          */
      /* DELIVERY TRANSIT LEAD-TIME (2.16.1).    */
      {pxrun.i &PROC='getDefaultTransitLTDays'
         &PROGRAM='sosoxr.p'
         &HANDLE=ph_sosoxr
         &PARAM="(input so_site,
           input ad_ctry,
           input ad_state,
           input ad_city,
           input """",
           output translt_days)" }

      substring(so_conrep,2,6) = string(translt_days,"999.99").

      end. /* end of create so_mstr                  */

      /* Scope bill_cm to "do" block to avoid unqualified fields of
      cm_mstr being interpreted without ambiguity while compiling */
      do for bill_cm:

         if not available bill_cm then
            find bill_cm where bill_cm.cm_addr = so_bill no-lock.

         if bill_cm.cm_cr_limit < bill_cm.cm_balance then do:

            /* CUSTOMER BALANCE */
            {pxmsg.i &MSGNUM=615 &ERRORLEVEL=2
                     &MSGARG1="bill_cm.cm_balance, ""->>>>,>>>,>>9.99"" "}

            /* CREDIT LIMIT */
            {pxmsg.i &MSGNUM=617 &ERRORLEVEL=1
                     &MSGARG1="bill_cm.cm_balance, ""->>>>,>>>,>>9.99"" "}

            if so_stat = "" and soc_cr_hold then do:
               /* SALES ORDER PLACED ON CREDIT HOLD */
               {pxmsg.i &MSGNUM=690 &ERRORLEVEL=1
                  &MSGARG1=getTermLabel(""SALES_ORDER"",25)}
               so_stat = "HD".
            end.

         end. /* if bill_cm.cm_cr_limit < bill_cm.cm_balance */

         if new so_mstr and bill_cm.cm_cr_hold then do:
            /* Customer on Credit Hold */
            {pxmsg.i &MSGNUM=614 &ERRORLEVEL=2}
            so_stat = "HD".
         end.

      end. /* do for bill_cm: */

      assign
         so_recid = recid(so_mstr)
         global_order = so_nbr
         endok = false.

      /* ADDED scx_shipto AND using_seq_schedules AS
      INPUT PARAMETERS and seq_sched_order AS
      OUTPUT PARAMETER TO rcsomte.p */
      /* HEADER DATA ITEMS */
   /* ADDED using_cust_consignment */
      {gprun.i ""rcsomte.p""
         "(input-output so_recid,
           input-output endok,
           input using_seq_schedules,
           input (input scx_shipto),
           input using_cust_consignment,
           output seq_sched_order,
           output socmmts)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      hide frame so2.

      if not endok then undo, leave.

      /* HEADER COMMENTS */
      assign
         global_lang = so_lang
         global_type = "".

      if socmmts = yes then do:
         cmtindx = so_cmtindx.
         global_ref = so_cust.
         {gprun.i ""gpcmmt01.p"" "(input ""so_mstr"")"}
/*GUI*/ if global-beam-me-up then undo, leave.

         so_mstr.so_cmtindx = cmtindx.
         view frame so.
      end.

   end. /* end of block_2                            */

   if endok then do:

      /* UPDATE REMOTE SO HEADER RECORD IF THERE IS ONE */
      {gprun.i ""rcrsoup.p"" "(input so_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      impexp_order = so_nbr.
      release so_mstr.

   /* ADDED using_cust_consignment */
      {gprun.i ""rcsomtb.p""
      "(input so_recid,
        input frame so scx_shipto,
        input using_cust_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* IMPORT EXPORT FLAG IS SET TO YES CALL THE IMPORT EXPORT DETAIL */
      /* LINE MAINTENANCE PROGRAM FOR USER TO UPDATE ied_det            */
      if not batchrun and impexp then do:

         impexp_edit = no.

         /* VIEW/EDIT IMPORT/EXPORT DATA */
         {pxmsg.i &MSGNUM=271 &ERRORLEVEL=1 &CONFIRM=impexp_edit}

         if impexp_edit then do:
            upd_okay = no.
            hide all.
            /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

            view frame so.
            {gprun.i ""iedmta.p""
               "(input ""1"",
                 input impexp_order,
                 input-output upd_okay )" }
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

      end.  /* if not batchrun */

   end. /* if endok */

end.
